package com.solveit.aps.io.db.activerecord;

import com.solveit.aps.io.db.Initializable;
import com.solveit.aps.io.db.InternalDbEntityHelper;
import com.solveit.core.db2.caching.EntityCollection;
import com.solveit.core.db2.query.builder.Query;

public class ActiveCollection<T>  extends EntityCollection<T> implements Initializable {
	private static ActiveCollection<?> instance;
	private Class<T> cl;
	
	public ActiveCollection(Class<T> cl) {
		super(cl);
		this.cl = cl;
		if (instance != null){
			instance = this;
		}
	}
	
	public static ActiveCollection<?> getInstance(){
		return instance;
	}

	@Override
	public void loadAtStartup() {
		Query.Select sel = new Query.Select(cl);
		// since this class is registered globally, the selected entities will
		// populate automatically.
		InternalDbEntityHelper.getInstance().exec(sel);
	}

}
